package com.dkm.biz.gl.persistence.entity;

import java.math.BigDecimal;
import java.util.Map;

import com.dkm.base.core.util.JsonUtil;
import com.dkm.base.core.util.string.StringUtils;
import com.dkm.biz.gl.constants.eav.DataType;

/**
 * 对象功能:系统参数配置 entity对象
 * 开发公司:唯心六艺软件 - Craft6.cn
 * 开发人员:winston
 * 创建时间:2014-09-13 11:13:48
 */
public class GlConfigPo extends GlConfigTbl{
	private BigDecimal shippingCount;
	private Double  shippingAmount;
	private BigDecimal  needShippingLine;
	private BigDecimal  fristNeedSshippingLine;
	private BigDecimal  difference;
	private Integer showType;
	
	
	public int getIntValue() {
		if(dataType.equals(DataType.INT.key())){
			return Integer.valueOf(value);
		}
		return -1;
	}
	
	public Map<String, Object> getOptionsMap(String callType){
		if(StringUtils.isEmpty(callType))callType="app";
		boolean findFlag = false;
		if(dataType.equals(DataType.OPTIONS.key())){
			 Object[] optionList=	JsonUtil.getDTOArray(options, Map.class);
			 if(optionList!=null&&optionList.length>0){
				for(int i=0;i<optionList.length;i++){
					Map<String, Object> map =(Map<String, Object>) optionList[i];
					findFlag = false;
					for(Map.Entry<String, Object> entry:map.entrySet()){
						if(entry.getKey().equals("type")&&entry.getValue().equals(callType)){
							findFlag=true;
							break;
						}
					}
					if(findFlag){
						 map =(Map<String, Object>) optionList[i];
						return map;
					}
				}
			 }
		}
		return null;
	}
	
	public String getImgSize(String callType,String picType){
		String imgSize="";
		if(StringUtils.isEmpty(picType))picType = "medium";
		if(StringUtils.isEmpty(callType))callType = "app";
		boolean findFlag = false;
		if(dataType.equals(DataType.OPTIONS.key())){
			 Object[] optionList=	JsonUtil.getDTOArray(options, Map.class);
			 if(optionList!=null&&optionList.length>0){
				for(int i=0;i<optionList.length;i++){
					Map<String, Object> map =(Map<String, Object>) optionList[i];
					findFlag = false;
					for(Map.Entry<String, Object> entry:map.entrySet()){
						if(entry.getKey().equals("type")&&entry.getValue().equals(callType)){
							findFlag=true;
							break;
						}
					}
					if(findFlag){
						 map =(Map<String, Object>) optionList[i];
						for(Map.Entry<String, Object> entry:map.entrySet()){
							if(entry.getKey().equals(picType)){
								imgSize=entry.getValue()+"";
								break;
							}
						}
						break;
					}
				}
			 }
		}
		return imgSize;
	}

	public BigDecimal getShippingCount() {
		return shippingCount;
	}

	public void setShippingCount(BigDecimal shippingCount) {
		this.shippingCount = shippingCount;
	}

	public Double getShippingAmount() {
		return shippingAmount;
	}

	public void setShippingAmount(Double shippingAmount) {
		this.shippingAmount = shippingAmount;
	}

	public BigDecimal getNeedShippingLine() {
		return needShippingLine;
	}

	public void setNeedShippingLine(BigDecimal needShippingLine) {
		this.needShippingLine = needShippingLine;
	}

	public BigDecimal getFristNeedSshippingLine() {
		return fristNeedSshippingLine;
	}

	public void setFristNeedSshippingLine(BigDecimal fristNeedSshippingLine) {
		this.fristNeedSshippingLine = fristNeedSshippingLine;
	}

	public Integer getShowType() {
		return showType;
	}

	public void setShowType(Integer showType) {
		this.showType = showType;
	}

	public BigDecimal getDifference() {
		return difference;
	}

	public void setDifference(BigDecimal difference) {
		this.difference = difference;
	}
}